#ifndef __STDTCPSERVER_H__
#define __STDTCPSERVER_H__
#include<string>
#include<iostream>
#include<memory>
using namespace std;
//结构体前置声明
struct StdTcpSocketPrivate;
struct StdTcpServerPrivate;
// 通信类
class stdTcpSocket
{
    public:
        //构造函数
        stdTcpSocket();
        // 析构函数
        ~stdTcpSocket();
    public:
        //连接服务器
        int connectToServer(const char *ip,int port);
        //是否连接成功
        bool Isconnectd() const;
        //发送信息
        int sendMessage(std::string &sendMsg);
        //发送信息
        int sendMessage(const void * sendMsg,size_t n);
        //接收信息
        int recvMessage(std::string &recvMsg);
        //接受信息
        int recvMessage(void * recvMsg,size_t n);
        //设置属性
        StdTcpSocketPrivate * getSockAttr();
    private:
        //智能指针
        std::unique_ptr<StdTcpSocketPrivate> m_sockAttr;
};

using stdTcpSocketPtr = std::shared_ptr<stdTcpSocket>;
// 监听类
class StdTcpServer
{
    public:
    //构造函数
        StdTcpServer();
    //析构函数
        ~StdTcpServer();
    public:
        //设置监听
        bool SetListen(int port);
        //接收连接
        std::shared_ptr<stdTcpSocket> getClientSock();

    private:
        //端口
        int m_port;
        //服务器的属性
        //智能指针
        std::unique_ptr<StdTcpServerPrivate> m_tcpAttr;
        
};

#endif